//
//  KYCalendarCellItem.m
//  KuaiyanCalendar
//
//  Created by 罗新 on 2017/10/18.
//  Copyright © 2017年 KuaiYan  Co.,LTD. All rights reserved.
//

#import "KYCalendarCellItem.h"
#import "KYCacheManager.h"
@implementation KYCalendarCellItem
+ (instancetype)calendarCellItemWithIconType:(CalendarIconType)type isHighLight:(BOOL)highLight year:(NSInteger)year month:(NSInteger)month day:(NSInteger)day continuityTime:(NSInteger)continutyTime{
    KYCalendarCellItem *item = [[KYCalendarCellItem alloc] init];
    item.iconType = type;
    item.highLight = highLight;
    item.year = year;
    item.month = month;
    item.day = day;
    item.continuityTime = continutyTime;
    return item;
}

- (void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeInteger:self.iconType forKey:@"iconType"];
    [aCoder encodeBool:self.highLight forKey:@"highLight"];
    [aCoder encodeInteger:self.year forKey:@"year"];
    [aCoder encodeInteger:self.month forKey:@"month"];
    [aCoder encodeInteger:self.day forKey:@"day"];
    [aCoder encodeInteger:self.continuityTime forKey:@"continuityTime"];
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self.iconType = [aDecoder decodeIntegerForKey:@"iconType"];
    self.highLight = [aDecoder decodeBoolForKey:@"highLight"];
    self.year = [aDecoder decodeIntegerForKey:@"year"];
    self.month = [aDecoder decodeIntegerForKey:@"month"];
    self.day = [aDecoder decodeIntegerForKey:@"day"];
    self.continuityTime = [aDecoder decodeIntegerForKey:@"continuityTime"];
    return self;
}
+ (BOOL)checkInCurrentDay{
    KYCacheManager *cacheMgr = [KYCacheManager shareInstance];
    NSDate *date = [NSDate date];
    NSString *checkKey = [NSString stringWithFormat:@"KYCalendar%ld%ld%ld",[NSDate year:date],[NSDate month:date],[NSDate day:date]];
    BOOL iscontain = [cacheMgr ky_isContainObjectForKey:checkKey];
    return iscontain;
}
+ (instancetype)currentDayCacheModel{
    KYCacheManager *cacheMgr = [KYCacheManager shareInstance];
    NSDate *date = [NSDate date];
    NSString *checkKey = [NSString stringWithFormat:@"KYCalendar%ld%ld%ld",[NSDate year:date],[NSDate month:date],[NSDate day:date]];
    BOOL iscontain = [cacheMgr ky_isContainObjectForKey:checkKey];
    if (iscontain) {
        return (KYCalendarCellItem *)[cacheMgr ky_ObjectForKey:checkKey];
    }else{
        return nil;
    }
}

@end
